package com.bit.dreamer;

import android.app.ActionBar;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.ViewFlipper;


public class PrologueActivity extends Activity implements OnTouchListener {

	private ViewFlipper m_viewFlipper;
	/** ViewFilpper 안에서 터치된 X축의 좌표 */
	private int m_nPreTouchPosX = 0;
	private SharedPreferences sf;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_prologue);
		
		ActionBar actionbar = getActionBar();
		actionbar.hide();
		
		

		m_viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
		m_viewFlipper.setOnTouchListener(this);

		// ViewFlipper에 서브 레이아웃 추가
		LinearLayout sub1 = (LinearLayout) View.inflate(this,
				R.layout.prologue1, null);
		LinearLayout sub2 = (LinearLayout) View.inflate(this,
				R.layout.prologue2, null);
		LinearLayout sub3 = (LinearLayout) View.inflate(this,
				R.layout.prologue3, null);
		LinearLayout sub4 = (LinearLayout) View.inflate(this,
				R.layout.prologue4, null);
		m_viewFlipper.addView(sub1);
		m_viewFlipper.addView(sub2);
		m_viewFlipper.addView(sub3);
		m_viewFlipper.addView(sub4);
	}

	private void MoveNextView() {
		m_viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
				R.anim.appear_from_right));
		m_viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
				R.anim.disappear_to_left));
		m_viewFlipper.showNext();
	}

	private void MovewPreviousView() {
		m_viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
				R.anim.appear_from_left));
		m_viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
				R.anim.disappear_to_right));
		m_viewFlipper.showPrevious();
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			m_nPreTouchPosX = (int) event.getX();
		}

		if (event.getAction() == MotionEvent.ACTION_UP) {
			int nTouchPosX = (int) event.getX();

			if (nTouchPosX < m_nPreTouchPosX) {
				MoveNextView();
			} else if (nTouchPosX > m_nPreTouchPosX) {
				MovewPreviousView();
			}

			m_nPreTouchPosX = nTouchPosX;
		}

		return true;
	}


}
